﻿#ifndef APPSETTINGSDATAMODELTYPEDEF_H
#define APPSETTINGSDATAMODELTYPEDEF_H


/** Data Example:

{
    "general": {
        "language": "zh_CN"
    },
    "log": {
        "maxline": 9001, "tag_filter": [0,1,2,3,4,5,6]
    },
    "cmd": {
        "default_loop": -1
    },
    "code": {
        "showmsg_top": true
    },
}

*/

#include "../IStore/IDataModelTypeDef.h"
#include "services/tlv/Base/tlv.h"
#include <QString>
#include <QList>


/*

#define FIELDS_GeneralSettingsModel(X) \
    X(QString,   language)

DEF_MODEL(GeneralSettingsModel, FIELDS_GeneralSettingsModel)



#define FIELDS_LogSettingsModel(X) \
    X(int,   maxline)

DEF_MODEL(LogSettingsModel, FIELDS_LogSettingsModel)



#define FIELDS_CmdSettingsModel(X) \
    X(int,   default_loop)

DEF_MODEL(CmdSettingsModel, FIELDS_CmdSettingsModel)



#define FIELDS_CodeSettingsModel(X) \
    X(bool,   showmsg_top)

DEF_MODEL(CodeSettingsModel, FIELDS_CodeSettingsModel)



#define FIELDS_AppSettingsModel(X)      \
    X(GeneralSettingsModel,   general)  \
    X(LogSettingsModel,       log)      \
    X(CmdSettingsModel,       cmd)      \
    X(CodeSettingsModel,      code)

DEF_MODEL(AppSettingsModel, FIELDS_AppSettingsModel)

*/


struct GeneralSettingsModel {
    QString language;
    QString background_imgae; // 背景图片路径
    bool show_guide = true;  // 是否要显示用户引导

    bool operator==(const GeneralSettingsModel& other) const {
        return language == other.language &&
               background_imgae == other.background_imgae &&
            show_guide == other.show_guide;
    }

    bool operator!=(const GeneralSettingsModel& other) const {
        return !(*this == other);
    }
};

struct LogSettingsModel {
    int maxline = 90001;
    QList<TlvTag> tag_filter = Tlv::allTags();

    bool operator==(const LogSettingsModel& other) const {
        return maxline == other.maxline &&
                tag_filter == other.tag_filter;
    }

    bool operator!=(const LogSettingsModel& other) const {
        return !(*this == other);
    }
};

struct CmdSettingsModel {
    int default_loop = -1;

    bool operator==(const CmdSettingsModel& other) const {
        return default_loop == other.default_loop;
    }

    bool operator!=(const CmdSettingsModel& other) const {
        return !(*this == other);
    }
};

struct CodeSettingsModel {
    bool showmsg_top = false;

    bool operator==(const CodeSettingsModel& other) const {
        return showmsg_top == other.showmsg_top;
    }

    bool operator!=(const CodeSettingsModel& other) const {
        return !(*this == other);
    }
};

struct AppSettingsModel {
    GeneralSettingsModel general;
    LogSettingsModel     log;
    CmdSettingsModel     cmd;
    CodeSettingsModel    code;

    bool operator==(const AppSettingsModel& other) const {
        return general == other.general &&
                log == other.log &&
                cmd == other.cmd &&
                code == other.code;
    }

    bool operator!=(const AppSettingsModel& other) const {
        return !(*this == other);
    }
};

#endif // APPSETTINGSDATAMODELTYPEDEF_H
